﻿using MediatRApp.IServices;
using MediatRApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediatRApp.Services
{
    public class UserService : IUserService
    {
        // 模拟数据库
        private readonly List<UserInfo> userList = new List<UserInfo>();
        private int nextId = 1;

        public Task<int> CreateUserAsync(UserInfo user)
        {
            user.UserId = nextId++;
            userList.Add(user);

            Console.WriteLine($"[数据库] 创建用户: {user.ToString()}");
            return Task.FromResult(user.UserId);
        }

        public Task<UserInfo> GetUserAsync(int userId)
        {
            Console.WriteLine($"[数据库] 查询用户 ID: {userId}");
            return Task.FromResult(userList.Find(u => u.UserId == userId));
        }

        public Task<List<UserInfo>> GetAllUsersAsync()
        {
            Console.WriteLine($"[数据库] 查询所有用户，共 {userList.Count} 个用户");
            return Task.FromResult(userList);
        }
    }
}
